<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%favorite}}".
 *
 * @property int $uid         用户id
 * @property int $house_id    房源id
 * @property int $create_time 添加时间
 */
class FavoriteModel extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%favorite}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'house_id'], 'required'],
            [['uid', 'house_id', 'create_time'], 'integer'],
            [['uid', 'house_id'], 'unique', 'targetAttribute' => ['uid', 'house_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uid' => '用户id',
            'house_id' => '房源id',
            'create_time' => '添加时间',
        ];
    }

    public function getHouse()
    {
        //hasMore
        return $this->hasOne(HouseModel::className(), ['id' => 'house_id']);
    }
}
